package com.ht.aems.fesservice.handler;



/**
 * Created by IntelliJ IDEA.
 * User: BaoHuping
 * Date: 2010-8-31
 */
public class QfcProtocolParser {//todo: not finished.

    public static String parseFrame(byte[] data) {
        StringBuffer result = new StringBuffer();
        int head = 0;
        int dataLen = data.length;
        if(dataLen > 150)
            dataLen = 150;//todo: wrong!
        String sTemp;
        int nTempLength;
        for (int j = 0; head + j < dataLen && j < dataLen + 2; j++) {
            sTemp = Integer.toHexString(data[head + j]);
            nTempLength = sTemp.length();
            if (nTempLength > 2)
                sTemp = sTemp.substring(nTempLength - 2, nTempLength);
            nTempLength = sTemp.length();
            if (nTempLength < 2)
                sTemp = "0" + sTemp;
            result.append(sTemp.toUpperCase()).append("  ");
            if ((j + 1) % 16 == 0)
                result.append("\n");
        }
        return result.toString();
    }

      public static String printeHex(byte[] data, int head, int dataLen) {
        StringBuffer result = new StringBuffer();
        String sTemp;
        int nTempLength;
        for (int j = 0; j < dataLen; j++) {
            sTemp = Integer.toHexString(data[head + j]);
            nTempLength = sTemp.length();
            if (nTempLength > 2)
                sTemp = sTemp.substring(nTempLength - 2, nTempLength);
            nTempLength = sTemp.length();
            if (nTempLength < 2)
                sTemp = "0" + sTemp;
            result.append(sTemp.toUpperCase()).append("  ");
            if ((j + 1) % 16 == 0)
                result.append("\n");
        }
        return result.toString();
    }
}
